package com.imufe.chemicalenterprisedangerwarning.controller;

import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import com.imufe.chemicalenterprisedangerwarning.entity.query.CheckQuery;
import com.imufe.chemicalenterprisedangerwarning.entity.query.CreateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.CheckDetailedVO;
import com.imufe.chemicalenterprisedangerwarning.exception.GlobalException;
import com.imufe.chemicalenterprisedangerwarning.service.CheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 检查表 前端控制器
 * </p>
 *
 * @author BaiBan
 * @since 2022-10-12
 */
@Api(tags = "检查")
@RestController
@RequestMapping("/check")
public class CheckController {

    @Autowired
    CheckService service;

    @ApiOperation(value = "新增", notes = "新增一个检查, 所有内容都可以取默认值,当用户有暂存检查时会删除暂存，添加一个新的")
    @PostMapping("/create")
    public ResponseEntity<CheckDetailedVO> create(@RequestBody @Validated(CreateGroup.class) CheckQuery query) {
        CheckDetailedVO detailedVO = service.create(query);
        return ResponseEntity.success(detailedVO);
    }

    @ApiOperation(value = "暂存", notes = "获取暂存记录; 一个用户只能有一个暂存")
    @PostMapping("/storage")
    public ResponseEntity<?> storage() throws GlobalException {
        CheckDetailedVO detailedVO = service.storage();
        return ResponseEntity.success(detailedVO);
    }

    @ApiOperation(value = "保存", notes = "获取保存记录; 一个用户只能有一个暂存")
    @PostMapping("/save")
    public ResponseEntity<?> save() {
        CheckDetailedVO detailedVO = service.save();
        return ResponseEntity.success(detailedVO);
    }
}